#!/usr/bin/env bash


if [ `whoami` != "root" ];then
  echo "must be root"
  exit 1
fi

which "docker" > /dev/null
if [ $? -eq 0 ]
then
    echo "docker已安装"
    exit 1
fi

# sudo apt-get remove docker docker-engine docker.io containerd runc

echo "安装docker..."
mkdir -p /etc/docker

cat <<EOF > /etc/docker/daemon.json
{
"registry-mirrors":[
    "https://hub-mirror.c.163.com",
    "https://registry.aliyuncs.com"
],
"graph":"/var/lib/docker",
"graph":"/var/lib/docker",
"insecure-registries":["localhost:8000"],
"features": { "buildkit": true }
}
EOF


wget -qO- https://get.docker.com/ | sh

sudo chmod a+rw /var/run -R

sudo gpasswd -a ${USER} docker
sudo systemctl restart docker

echo "已安装 docker 为开机启动，并启动了 docker "


# 设置存储位置，需要提前执行以下命令
# mkdir -p /data/docker
# ln -s /data/docker /var/lib/docker
